import cv2
import os

import numpy
import numpy as np
import processImage
import Home

# arr1=[[0,0 ,0 ,2 ,0], [0, 5, 0, 0, 0], [0, 0 ,7 ,0 ,0], [0, 9, 0, 0, 0], [0, 0 ,0 ,0 ,0]]
# arr2=[[0,0 ,0 ,0 ,0], [0, 0, 0, 0, 0], [0, 0 ,0 ,0 ,0], [0, 0, 0, 0, 0], [0, 0 ,0 ,0 ,0]]
# for i in range(len(arr1)):
#     print(len([x for x in arr1[i] if x in arr2[i]]))




def differenec_rat(draw_mask,image_mask):
    sum=0
    draw_mask=cv2.cvtColor(draw_mask, cv2.COLOR_BGR2GRAY)
    image_mask=cv2.cvtColor(image_mask, cv2.COLOR_BGR2GRAY)
    # cv2.imshow("draw_mask",draw_mask)
    # cv2.imshow("image_mask",image_mask)
    # cv2.waitKey(0)
    sub=(image_mask==draw_mask)#返回的是true和false

    sum=np.sum(sub!=0)
    # for i in range(0,draw_mask.shape[0]):
    #     arr1=image_mask[i]
    #     arr2=draw_mask[i]
    #     print(arr2.shape)
    #     sum=sum+len([x for x in arr1[i] if x in arr2[i]])
    all=draw_mask.shape[0]*draw_mask.shape[1]
    #print("sum,all",sum,all)
    return sum/all